<?php include("common/conn.php");
  // var_dump($_SESSION['shopid']);die;
  //对指定商家的所有商品，销售价、原价 和 规格价，进行批量修改
  if($_GET['modifyPrice']=="ok")
  {
      try {   
        $shopid = $_REQUEST[shopid];
        $rate = $_REQUEST[rate];
        $query = mysql_query("select * from goods where shopid=".$shopid);
        while ($row = mysql_fetch_assoc($query)) {
          $price = round((100+$rate)/100*$row[price],1);
          // $yuanjia = round((100+$rate)/100*$row[yuanjia],1);
          mysql_query("UPDATE goods set price=".$price." where goodsid=".$row[goodsid]);
          //修改该商品所有规格的价格
          $query1 = mysql_query("select * from goodsselect where goodsid=".$row[goodsid]);
          while ($row1 = mysql_fetch_assoc($query1)) {
            $price = (100+$rate)/100*$row1[price];
            mysql_query("UPDATE goodsselect set price=".$price." where selectid=".$row1[selectid]);
          }
        }
        echo 1;die;
      } catch (Exception $e) {
        echo -1;die;
      }   
  }

//对指定商家的所有原价进行批量修改
  if($_GET['original_price']=="ok")
  {
      try {   
        $shopid = $_REQUEST['shopid'];
        $rate = $_REQUEST['rate'];
        $query = mysql_query("select * from goods where shopid=".$shopid);
        while ($row = mysql_fetch_assoc($query)) {
          $yuanjia = round((100+$rate)/100*$row['yuanjia'],1);
          mysql_query("UPDATE goods set yuanjia=".$yuanjia." where goodsid=".$row['goodsid']);
        }
        echo 1;die;
      } catch (Exception $e) {
        echo -1;die;
      }   
  }

  if ($_GET['cancel']='ok') {
    $srat1=mysql_query("DELETE FROM ad where id='".$_GET['id']."'");
  }
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

  <title>e网批发管理后台</title>
<?php 
  // 营业与否
  if ($_REQUEST[open] != '') {
    $res = mysql_query("UPDATE shop set open = " . $_REQUEST[open] . " where shopid= " . $_REQUEST[shopid]);
    echo "<script>window.location.href='shequ.php?cityid=0&categroyid=0'</script>";
  }
  // 营业与否 end

  // 查询全部社区
  $query = mysql_query("select * from city");
  while ($row = mysql_fetch_assoc($query)) {
    $citys[] = $row;
  }
  // 查询全部社区 end

  // 查询全部分类
  $query = mysql_query("select * from categroy");
  while ($row = mysql_fetch_assoc($query)) {
    $categroys[] = $row;
  }
  // 查询全部分类 end
?>
<script type="text/javascript" src="js/jquery.min.js"></script>
<link href="css/styles.css" rel="stylesheet" type="text/css" />
<link href="css/style2.css" rel="stylesheet" type="text/css" />
<script type="text/JavaScript">
  function MM_jumpMenu(targ,selObj,restore){ //v3.0
    eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
    if (restore) selObj.selectedIndex=0;
  }
</script>
</head>
<body>
<!-- 13924075438 -->
  <!--header-->
  <?php include("common/header.php");?>
  <!--header end-->

  <!-- staqrt subnav -->
  <div id="sub_nav">
    <div id="subnav_wrap" class="container_12">
      <div id="subnav" class=" grid_12">
        <ul>
          <li><a href="shequ.php?cityid=0&categroyid=0" class="sub_nav_active">厂商管理</a></li>
        </ul>
      </div>
    </div>
  </div>
  <div class="container_12" style="background: #fff; border:0px;">
  </div>
    <form id="form" action="?cityid=0&categroyid=0&del=ok&shopid=<?php  echo $_REQUEST[shopid]; ?>" method="post">
      <table width="100%" border="0" cellpadding="0" cellspacing="0">
        <tr>
          <th width="5%" scope="col">
            <input type="checkbox" name="checkbox" id="checkbox" class="checkall" /><label for="checkbox"></label></th>
            <!-- <th width="13%" scope="col">是否通过审核</th> -->
            <!-- <th width="8%" scope="col">审核状态</th> -->
            <th width="8%" scope="col">注册手机号码/登录账号</th>
            <th width="8%" scope="col">名称</th>
            <th width="8%" scope="col">厂商代码/登录账号</th>
            <th width="8%" scope="col">地址</th>
            <th width="16%" scope="col">市场</th>
            <th width="8%" scope="col">分类</th>
            <th width="8%" scope="col">商品</th>
            <th width="8%" scope="col">推荐商家</th>
            <th width="15%" scope="col">操作</th>
          </tr>

<?php 
mysql_query('SET NAMES UTF8');
$sql = "SELECT a.phone, a.name, a.shop_daima, a.address, a.recommend, a.open, b.city, COUNT(c.goodsid) AS num FROM shop AS a LEFT JOIN city AS b ON a.`city` = b.`id` LEFT JOIN goods AS c ON a.`shopid` = c.`shopid` WHERE c.`shopid` = " . $_SESSION['shopid'];
$shop = mysql_fetch_assoc(mysql_query($sql));
?>
  <tr>
      <td width="5%" scope="col">
          <input type="checkbox" name="checkbox[]" id="checkbox" class="checkbox" value="<?php echo $shop['shopid'];?>"/>
      </td>
      <td width="8%" scope="col">
          <?php echo $shop['phone'];?>
      </td>
      <td width="8%" scope="col">
          <?php echo $shop['name'];?>
      </td>
      <td width="8%" scope="col">
          <?php echo $shop['shop_daima'];?>
      </td>
      <td width="8%" scope="col">
          <?php echo $shop['address'];?>
      </td>
      <td width="16%" scope="col">
          <?php echo $shop['city'];?>
      </td>
      <td width="8%" scope="col">
          <?php echo $shop['name'];?>
      </td>
      <td width="8%" scope="col">
          <?php echo $shop['num'];?>
      </td>
       <td width="8%" scope="col">
        <?php if ($shop['recommend'] == 1) {
          echo "是";
        }else{
          echo "否";
        } ?>
      </td>
      <td width="15%" scope="col">
          <div class="youse2">
              <a href="addshop.php?id=<?php echo $_SESSION['shopid'];?>">编辑商家</a>
          </div>
          <div class="youse2">
              <a href="javascript:modifyPrice(<?php echo $_SESSION['shopid'];?>);">批量修改价格</a>
          </div>
          <div class="youse2">
              <a href="javascript:original_price(<?php echo $_SESSION['shopid'];?>);">批量修改原价</a>
          </div>
          <div class="youse">
              <a href="goods2.php?shopid=<?php echo $_SESSION['shopid'];?>">管理商品</a>
          </div>
          <div class="youse2">
              <a href="shopyouhui.php?shopid=<?php echo $_SESSION['shopid'];?>">商家优惠券</a>
          </div> 

          
          <?php if($shop['open'] == 1) { ?>
              <div class="youse">
                  <a href="?open=0&shopid=<?php echo $_SESSION[shopid];?>">停业</a>
              </div>
          <?php }else if($shop['open'] == 0) {?>
              <div class="youse2">
                  <a href="?open=1&shopid=<?php echo $_SESSION[shopid];?>">营业</a>
              </div>
          <?php } ?>
      </td>
  </tr>

</table>
</form>
<!-- END TABULAR DATA EXAMPLE -->   

</div>
<input type="hidden" id="shopid" value="<?php echo $_SESSION['shopid']; ?>">
<!-- end content wrap -->

</body>
<!-- 对话框插件 -->
<script src="js/artDialog/jquery.artDialog.js?skin=twitter"></script>
<script src="js/artDialog/plugins/iframeTools.js"></script>
<!-- 表单库插件 -->
<script type="text/javascript" src="js/jquery.form.min.js"></script>
<script type="text/javascript">

  var shopid = $('#shopid').val();

  function add(){
    window.location.href="addshop.php?shopid="+shopid;
  }

  var cityVal = $('.citys').val();
  
  // 页面跳转 
  $('.skip').click(function(){
    var page = $('.skip_val').val();
    var url = "shequ.php?page="+page+"&keywords=<?php echo $_REQUEST[keywords]; ?>&cityid=<?php echo  $_REQUEST[cityid];?>&categroyid=<?php echo $_REQUEST[categroyid]; ?>"
    // var url = "shequ.php?page="+page;
    window.location.href = url;
  })
  // 页面跳转 end
  
  //批量修改价格
   function  modifyPrice(shopid){
    $.dialog({
          title: '批量修改价格',
          content: "<form  id='purview'><input  id='modifyPrice_id'  type='text' placeholder='百分比（如：-5 或 5）' class='text'/><br/><span id='tips'  style='color:red'></span></form>",
          ok: function () {
              $("#tips").html("请稍后，批量修改中...");
              var rate = $("#modifyPrice_id").val();
              $("#purview").ajaxSubmit({
                  url:'?modifyPrice=ok&rate='+rate+'&shopid='+shopid,
                  type:"get",
                  success:function(data){
                      $("#tips").html("批量修改成功");
                      alert('更新成功');
                  }           
              });
              return false;
          },
          okVal:'提交',
          cancel: true,
          cancelVal:'取消',
          close:function(){
             window.location.href = "?cityid=0&categroyid=0&time="+new Date().getTime();
          }
      });
   }

  //批量修改价格
   function  original_price(shopid){
    $.dialog({
          title: '批量修改原价',
          content: "<form  id='purview'><input  id='original_price'  type='text' placeholder='百分比（如：-5 或 5）' class='text'/><br/><span id='tips'  style='color:red'></span></form>",
          ok: function () {
              $("#tips").html("请稍后，批量修改中...");
              var rate = $("#original_price").val();
              $("#purview").ajaxSubmit({
                  url:'?original_price=ok&rate='+rate+'&shopid='+shopid,
                  type:"get",
                  success:function(data){
                      $("#tips").html("批量修改成功");
                      alert('更新成功');
                  }           
              });
              return false;
          },
          okVal:'提交',
          cancel: true,
          cancelVal:'取消',
          close:function(){
             window.location.href = "?cityid=0&categroyid=0&time="+new Date().getTime();
          }
      });
   }
</script>
</html>
